package nz.ac.massey.cs.compile;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import nz.ac.massey.cs.domain.Cell;
import nz.ac.massey.cs.domain.IConstraint;

import org.java.plugin.Plugin;

public class UniqueConstraint extends AbstractConstraint{
	
	/* (non-Javadoc)
	 * @see tims.domain.IConstraint#isViolated()
	 */
	@Override
	public boolean isViolated()
	{
		ArrayList<Cell> cells = getCells();
		for(Cell a:cells)
		{
			String ValueA = a.getValue(); 
			if(!ValueA.equals(""))
			{
				for(Cell b:cells) 
				{
					String ValueB = b.getValue();
					if(!ValueB.equals("") && a != b)
					{
						if(ValueA.equals(ValueB) || !Range.contains(ValueA) || !Range.contains(ValueB))
						{
							return true;
						}
					}
				}
			}
		}
		return false;
	}
	@Override
	public void applyConstraintInfo(String constraintInfo) {
		Map<String,String> drawingInfo = getDrawingInfo();
		if(constraintInfo != "")
		{
			String[] splitedData = constraintInfo.split(",");
			drawingInfo.put("Type", splitedData[0]);
			drawingInfo.put("Border-Colour", splitedData[1]);
		}
	}
	/* (non-Javadoc)
	 * @see tims.domain.IConstraint#isSatisfied()
	 */
	@Override
	public boolean isSatisfied()
	{
		ArrayList<Cell> cells = getCells();
		for(Cell a:cells)
		{
			if(a.getValue().equals(""))
			{
				return false;
			}
		}
		return isViolated();
	}

	@Override
	protected void doStart() throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void doStop() throws Exception {
		// TODO Auto-generated method stub
		
	}

	
}
